package com.car.carmgr.service.impl;

import com.car.carmgr.bean.Rent;
import com.car.carmgr.mapper.CarMapper;
import com.car.carmgr.mapper.RentMapper;
import com.car.carmgr.service.RentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RentServiceImpl implements RentService {

    @Autowired
    private RentMapper rentMapper;

    @Autowired
    private CarMapper carMapper;

    @Override
    public int insertRent(Rent rent) {
        int i = rentMapper.insertRent(rent);
        int j = carMapper.updateCarStatus(rent.getCarNumber(),"1");
        return i+j;
    }

    @Override
    public PageInfo<Rent> findAll(Rent rent, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Rent> list = rentMapper.findAll(rent);
        PageInfo<Rent> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int getCount(Rent rent) {
        return rentMapper.getCount(rent);
    }


}
